<div class="" id="container">

    <div class="row">

        <div class="col-lg-12">

            <div class="panel">
                <!--<div class="panel-heading">
                    <h4>Preferences</h4>
                </div>-->
                <div class="panel-body">

                    <?php 
                    $flash = $this->Session->flash();
                    
                    if( $flash ) {
                        echo "<div class='alert alert-success'>"
                                . "<button class='close' data-dismiss='alert'><i class='fa fa-times'></i></button>"
                                . "$flash"
                           . "</div>";
                    }
                    ?>
                    
                    <form action="<?php echo $this->Html->url(array('action' => 'preferences')); ?>" method ="post" id="preferences-form" class="form form-horizontal">

                        <?php 
                        $i = 0;
                        foreach($preferences as $preference) { ?>
                        
                            <div class="form-group">
                                <div class="col-lg-5 control-label">
                                    <?php echo $preference['SettingType']['description']; ?>
                                </div> 
                                <div class="col-lg-7 controls">
                                    <?php 
                                    $name = $preference['OrganisationSetting']['setting_type_id'];
                                    $value = $preference['OrganisationSetting']['value'];
                                    switch($preference['SettingType']['type']) {
                                        case 'text':
                                        case 'email':
                                            echo "<input type='text' name='OrganisationSetting[$i][value]' class='form-control input-sm input-s' value='$value' />";
                                            break;
                                        
                                        case 'number':
                                            echo "<input type='number' name='OrganisationSetting[$i][value]' class='form-control input-sm input-s-xs' value='$value' />";
                                            break;
                                        
                                        case 'flag':
                                            $checked = $value == 1 ? "checked=checked" : "";
                                            echo "<label class='switch'>"
                                                . "<input type='checkbox' name='OrganisationSetting[$i][value]' value='1' $checked />"
                                                . "<span></span>"
                                                . "</label>";
                                            break;
                                        
                                        case 'date':
                                        case 'datetime':
                                            $type = $preference['SettingType']['type'];
                                            echo "<input type='text' name='OrganisationSetting[$i][value]' class='form-control datepicker-input input-sm input-s' value='$value' data-date-format='yyyy-mm-dd' />";
                                            break;
                                    }
                                    
                                    echo "<input type='hidden' name='OrganisationSetting[$i][id]' value='{$preference['OrganisationSetting']['id']}' />";
                                    
                                    $i++;
                                    ?>
                                </div>
                            </div>
                        <?php } ?>

                        <div class="form-group m-t-lg">
                            <div class="col-lg-5 control-label">
                                &nbsp;
                            </div> 
                            <div class="col-lg-7 controls">
                                <input type="submit" class="btn btn-sm btn-info" value="Save Changes" />
                                <input type="button" class="btn btn-sm btn-white" value="Cancel" />
                            </div>
                        </div>
                </div>
            </div>
        </div>
    </div>
</div>